const getDefaultState = () => {
  return {
    uniqueId: '',
    name: '',
    avatar: '',
    roles: [],
    recommendCode: '',
    loginInfo: {}
  };
};

const state = getDefaultState();

const mutations = {
  // 设置角色
  setRoles: (state, roles) => {
    state.roles = roles;
  },
  // 退出登录
  signOut: (state, path) => {
    let loginOrigin = process.env.VUE_APP_LOGIN_APP_ORIGIN;

    if (path) {
      // 登录成功后需要跳转回来
      let redirect = window.location.pathname;
      let hash = window.location.hash;
      hash = hash.replace('#/', '');
      loginOrigin = `${loginOrigin}?redirect=${redirect}&hash=${hash}`;
    }
    // 重置参数
    Object.assign(state, getDefaultState());
    localStorage.removeItem('token');
    window.location.href = loginOrigin;
  }
};

const actions = {};

export default {
  namespaced: true,
  state,
  mutations,
  actions
};
